

$(function () {
    //悬浮窗的总价
    var sum = $("#sum");
    var car = $(".cars");
    var user= localStorage.getItem("user");
    var div = $(".un_login");
    var number = $("#number");
    var car_bg = $(".car_bg");
    //总价格
    var priceSum = $("#priceSum");
    if(user!=null){
        div.html(user+"的购物车");
    }else if(car.length==0){
        car.html("购物车空空如也");
    }else if(user==null){
        car_bg.html("");
        car_bg.html("请先登录再使用购物车&nbsp;<a href='Login.html'><font color='red'>登录</font></a>");
    }
    //show();
    //悬浮框展示内容
    function show(){
        var userName = localStorage.getItem("user");
        // var car = $(".cars");
        $.ajax({
            url : "easybuy/cart/showItem",
            dataType: "json",
            type : "post",
            data : {"userName" : userName},
            success : function (data) {
                var th = "";
                var sumprice = 0;
                if(data.length==0){
                    car.html("您还未添加商品");
                }
                for(var i=0;i<data.length;i++){
                    th +="<li><div class='img'><a href=''><img src='../images/"+data[i].product.fileName+"' width=\"58\" height=\"58\" /></a></div>";
                    th +="<div class='name'><a href=''>"+data[i].product.name+"</a></div>";
                    th +="<div class='price'>"+accounting.formatMoney(data[i].product.price, "￥",1, ",", ".")+"&nbsp;×&nbsp;<span>"+data[i].quantity+"</span></div>";
                    th +="<div class='productCost'>"+accounting.formatMoney(data[i].cost, "￥",1, ",", ".")+"</div></li>";

                    sumprice+=data[i].cost;
                    //$(".quantity").val(data[i].quantity);
                }
                number.html(data.length);
                sum.html(accounting.formatMoney(sumprice, "￥",1, ",", "."));
                car.html("");
                car.append(th);
            },
            error : function (XMLHttpRequest, textStatus, errorThrown) {
                //alert("出现错误");
                console.log(XMLHttpRequest.status);
                console.log(XMLHttpRequest.readyState);
                console.log(textStatus);
            }
        });
    }
    //表格内容展示
    function viewCar(){


    }

});